﻿using System;
using System.Collections.Generic;
using System.Linq;
using DomainModel;
using Repository.Abstract;
using Services.Abstract;

namespace Services.Concrete
{
    public class WorkTypeService : Service<WorkType>, IWorkTypeService
    {
        private readonly IWorkTypeRepository _worktypeRepository;

        public WorkTypeService(IWorkTypeRepository worktypeRepository)
            : base(worktypeRepository)
        {
            _worktypeRepository = worktypeRepository;
        }

        public WorkType Get(Subject subject, string name)
        {
            if (subject == null)
                throw new ArgumentNullException("subject");
            if (name == null || string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            return _worktypeRepository.GetBySubjectAndName(subject, name);
        }

        public List<WorkType> Get(Subject subject, int moduleNo)
        {
            if (subject == null)
                throw new ArgumentNullException("subject");
            if (moduleNo <= 0)
                return null;

            return _worktypeRepository.GetBySubjectAndModuleNo(subject, moduleNo).ToList();
        }

        /*public WorkType GetWorkType(Subject subject, string workTypeName)
        {
            if (subject == null || string.IsNullOrWhiteSpace(workTypeName))
                return null;

            return DAOFactory.DEFAULT.WorkTypeDAO.GetBySubjectAndName(subject, workTypeName);
        }

        public List<WorkType> GetWorkTypes(Subject subject, int moduleNo)
        {
            if (subject == null || moduleNo <= 0)
                return null;

            return DAOFactory.DEFAULT.WorkTypeDAO.GetBySubjectAndModuleNo(subject, moduleNo).ToList();
        }

        public void Save(WorkType entity)
        {
            if (entity == null)
                return;

            DAOFactory.DEFAULT.WorkTypeDAO.SaveOrUpdate(entity);
        }

        public void Delete(WorkType entity)
        {
            if (entity == null)
                return;

            DAOFactory.DEFAULT.WorkTypeDAO.Delete(entity);
        }

        public WorkType GetById(long id)
        {
            if (id <= 0)
                return null;

            return DAOFactory.DEFAULT.WorkTypeDAO.GetById(id);
        }

        public List<WorkType> GetAll()
        {
            return DAOFactory.DEFAULT.WorkTypeDAO.GetAll().ToList();
        }*/
    }
}